package de.stefanocke.roo.wicket.registry;

import java.util.Set;

import org.springframework.roo.metadata.MetadataItem;
import org.springframework.roo.model.JavaType;

/**
 * 
 * Registry to register and find Wicket metadata for a certain model class.
 * 
 */
public interface MetadataRegistry {

	/**
	 * Finds Wicket Metadata. The search migth be restricted to a certain
	 * metadata type
	 * and / or a model class.
	 * Also registers dependencies to get informed, when such metadata
	 * becomes available or goes away.
	 * 
	 * @param clientMid
	 *            the requesting Metadata ID
	 * @param classOrKind
	 *            if not null, the search is restricted to that class or kind
	 *            metadata
	 * @param modelClass
	 *            if not null, the search is restricted to metadata related to
	 *            this modelClass
	 * @return the set of found MIDs
	 */
	Set<String> findMetadata(String clientMid, Class<?> classOrKind, JavaType modelClass);

	void registerMetadata(MetadataItem metadataItem);

	void deregisterMetadata(String mid);

	/**
	 * 
	 * @param kind
	 *            the metadata kind. Should be an interface implemented by
	 *            metadataClass
	 * @param metadataClass
	 *            the metadata class
	 * @param triggers
	 */
	void registerMetadataClass(Class<?> kind, Class<?> metadataClass, Set<Class<?>> triggers);

	void deregisterMetadataClass(Class<?> metadataClass);

	/**
	 * Gets all Wicket metadata that depends on the given upstreamMetadataItem.
	 * 
	 * @param upstreamMetadataItem
	 * @return
	 */
	Set<String> getDependentMetadata(MetadataItem upstreamMetadataItem);

	/**
	 * Gets the Wicket metadata, that depends on a given modelClass.
	 * 
	 * @param wicketMetadataClass
	 *            if null, then all WicketMetadata that depends on modelClass is
	 *            returned. If not null,
	 *            than only Wicket Metadata, that has searched for that type of
	 *            other Wicket Metadata is returned.
	 * @param modelClass
	 *            the modelClass
	 * 
	 * @return
	 */
	@Deprecated
	Set<String> getDependentMetadata(Class<?> wicketMetadataClass, JavaType modelClass);

}
